package com.bite.book.controller;

import com.bite.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session){
       log.info("接收到参数:"+name);
        //1. 校验参数格式
        //2. 从数据库中校验账号和密码是否正确, 但是当前未学习数据库的操作, 暂且写死
        //3. 如果正确, 存储session, 返回true
        Boolean result = userService.checkUserAndPassword(name, password, session);
        log.info("用户登录结果, name:{}, 结果: {}", name, result);
        return result;
    }
}
